package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	public class TankBody
	{
		//
		public var name:String = "body";
		//
		private var m_pTexture:BitmapData = null;
		//
		private var m_iMaxSpeed:Number = 2;//最大速度
		private var m_iMaxRad:Number = 1;//最大角速度
		private var m_iAddSpeed:Number = 0.4;//加速度
		//
		private var m_iDefFront:Number = 100;//前装甲
		private var m_iDefSide:Number = 40;//侧装甲
		private var m_iDefBack:Number = 20;//背装甲
		private var m_iDefHead:Number = 20;//顶装甲
		//
		private var m_iHoldPoint:Number = 100;//耐久  -抵消伤害
		private var m_iDefPoint:Number = 100;//装甲值 -归0时损毁
		//
		private var m_iWidth_2:Number = 0;	//车体半宽
		private var m_iHeight_2:Number = 0;//车体半长
		private var m_iFootWidth:Number = 1;//履带宽度,画阴影用
		private var m_iGunX:Number = 0;//炮塔位置
		private var m_iGunY:Number = 0;
		//
		//访问方法
		public function get bmpData():BitmapData{
			return m_pTexture.clone();// 可能太浪费内存了
		}
		public function get maxSpeed():Number{
			return m_iMaxSpeed;
		}
		public function get maxRad():Number{
			return m_iMaxRad;
		}
		public function get addSpeed():Number{
			return m_iAddSpeed;
		}
		public function defend( i:int ):Number{
			switch(i){
				case 0:
					return m_iDefFront;	//一般这个总是最硬的
				case 1:
				case 2:
					return m_iDefSide;
				case 3:
					return m_iDefBack;
				default:
					return m_iDefHead;	//默认返回顶部装甲,意味相当脆弱
			}
		}
		public function maxHP():Number{
			return m_iHoldPoint;
		}
		public function maxDP():Number{
			return m_iDefPoint;
		}
		public function get width():Number{
			return m_iWidth_2;
		}
		public function get height():Number{
			return m_iHeight_2;
		}
		public function get gunSetX():Number{
			return m_iGunX;
		}
		public function get gunSetY():Number{
			return m_iGunY;
		}
		public function get footWidth():Number{
			return m_iFootWidth;
		}
		//
		public function TankBody( xml:XML )//通过XML来初始化吧
		{
			var texFileName:String = xml.@file;
			var load:rLoader = new rLoader( texFileName, Init );
			name=xml.@name;
			m_iMaxSpeed=xml.@maxSpeed;//最大速度
			m_iMaxRad=xml.@maxRad;//最大角速度
			m_iAddSpeed=xml.@addSpeed;//加速度
			m_iDefFront=xml.@defFront;//前装甲
			m_iDefSide=xml.@defSide;//侧装甲
			m_iDefBack=xml.@defBack;//背装甲
			m_iDefHead=xml.@defHead;//顶装甲
			m_iHoldPoint=xml.@hp;//耐久值
			m_iDefPoint=xml.@dp;//装甲值
			m_iFootWidth=xml.@footWidth;//履带宽度
		}
		//
		private function Init( e:Event ):void{//装载纹理完成后
			var bmp:Bitmap = e.target.content as Bitmap;
			m_pTexture = bmp.bitmapData;
			m_iWidth_2 = m_pTexture.width*0.5;
			m_iHeight_2 = m_pTexture.height*0.5;
			m_iGunX-=m_iHeight_2;
		}

	}
}